package com.corona.game;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Vector2;
import com.corona.Game;
import com.corona.game.util.TextureCache;
import java.util.ArrayList;

/* compiled from: Battle.java */
/* loaded from: pokewilds.jar:com/pkmngen/game/ThrowOutPokemonCrystal.class */
public class ThrowOutPokemonCrystal extends Action {
    Sprite pokeballSprite;
    ArrayList<Vector2> positions;
    Vector2 position;
    ArrayList<Sprite[][][]> sprites;
    Sprite[][][] sprite;
    ArrayList<Integer> repeats;
    ArrayList<String> sounds;
    String sound;
    Sprite helperSprite;
    public Action.Layer layer = Action.Layer.gui_104;
    boolean doneYet = false;

    public ThrowOutPokemonCrystal(Game game, Action nextAction) {
        super(new Object[0]);
        this.nextAction = nextAction;
    }

    @Override // com.corona.game.Action
    public String getCamera() {
        return "gui";
    }

    @Override // com.corona.game.Action
    public Action.Layer getLayer() {
        return this.layer;
    }

    /* JADX DEBUG: Multi-variable search result rejected for r1v30, resolved type: com.badlogic.gdx.graphics.g2d.Sprite[][][] */
    /* JADX DEBUG: Multi-variable search result rejected for r1v32, resolved type: com.badlogic.gdx.graphics.g2d.Sprite[][][] */
    /* JADX DEBUG: Multi-variable search result rejected for r1v34, resolved type: com.badlogic.gdx.graphics.g2d.Sprite[][][] */
    /* JADX DEBUG: Multi-variable search result rejected for r1v36, resolved type: com.badlogic.gdx.graphics.g2d.Sprite[][][] */
    /* JADX WARN: Multi-variable type inference failed */
    @Override // com.corona.game.Action
    public void firstStep(Game game) {
        this.position = new Vector2(16.0f, 48.0f);
        TextureRegion[][] tempRegion = new Sprite((Sprite) game.player.currPokemon.backSprite).split(8, 8);
        Object[][] objArr = new Sprite[6][6][];
        for (int i = 0; i < tempRegion.length; i++) {
            for (int j = 0; j < tempRegion[i].length; j++) {
                objArr[i][j] = new Sprite(tempRegion[5 - j][i]);
            }
        }
        for (int i2 = 0; i2 < objArr.length; i2++) {
            objArr[i2][1] = objArr[i2][2];
            objArr[i2][2] = objArr[i2][3];
            objArr[i2][3] = objArr[i2][5];
            objArr[i2][4] = null;
            objArr[i2][5] = null;
        }
        objArr[1] = objArr[0];
        objArr[0] = new Sprite[0];
        objArr[4] = objArr[5];
        objArr[5] = new Sprite[0];
        Object[][] objArr2 = new Sprite[6][6][];
        for (int i3 = 0; i3 < objArr.length; i3++) {
            for (int j2 = 0; j2 < objArr[i3].length; j2++) {
                objArr2[i3][j2] = objArr[i3][j2];
            }
        }
        for (int i4 = 0; i4 < objArr2.length; i4++) {
            if (objArr2[i4].length > 0) {
                objArr2[i4][1] = objArr2[i4][3];
                objArr2[i4][2] = null;
                objArr2[i4][3] = null;
                objArr2[i4][4] = null;
                objArr2[i4][5] = null;
            }
        }
        objArr2[2] = objArr2[1];
        objArr2[1] = new Sprite[0];
        objArr2[3] = objArr2[4];
        objArr2[4] = new Sprite[0];
        objArr2[5] = new Sprite[0];
        Texture text = TextureCache.get(Gdx.files.internal("poof_sheet2.png"));
        this.sprites = new ArrayList<>();
        this.sprites.add(null);
        this.sprites.add(new Sprite[][][]{null, new Sprite[][]{new Sprite[]{new Sprite(text, 0, 0, 48, 48)}}});
        this.sprites.add(new Sprite[][][]{null, new Sprite[][]{new Sprite[]{new Sprite(text, 48, 0, 48, 48)}}});
        this.sprites.add(new Sprite[][][]{objArr2, new Sprite[][]{new Sprite[]{new Sprite(text, 48, 0, 48, 48)}}});
        this.sprites.add(new Sprite[][][]{objArr2, new Sprite[][]{new Sprite[]{new Sprite(text, 96, 0, 48, 48)}}});
        this.sprites.add(new Sprite[][][]{objArr, new Sprite[][]{new Sprite[]{new Sprite(text, 96, 0, 48, 48)}}});
        this.sprites.add(new Sprite[][][]{objArr, new Sprite[][]{new Sprite[]{new Sprite(text, 144, 0, 48, 48)}}});
        this.sprites.add(new Sprite[][][]{new Sprite[][]{new Sprite[]{game.player.currPokemon.backSprite}}, new Sprite[][]{new Sprite[]{new Sprite(text, 144, 0, 48, 48)}}});
        this.sprites.add(new Sprite[][][]{new Sprite[][]{new Sprite[]{game.player.currPokemon.backSprite}}});
        this.sprites.add(new Sprite[][][]{new Sprite[][]{new Sprite[]{game.player.currPokemon.backSprite}}});
        this.repeats = new ArrayList<>();
        this.repeats.add(34);
        this.repeats.add(4);
        this.repeats.add(2);
        this.repeats.add(2);
        this.repeats.add(2);
        this.repeats.add(2);
        this.repeats.add(2);
        this.repeats.add(2);
        this.repeats.add(26);
        this.sounds = new ArrayList<>();
        this.sounds.add(null);
        this.sounds.add("poof1");
        for (int i5 = 0; i5 < 9; i5++) {
            this.sounds.add(null);
        }
        game.battle.drawAction.drawFriendlyPokemonAction = this;
        game.player.currPokemon.resetStatStages();
        game.player.currPokemon.disabledIndex = -1;
        game.player.currPokemon.disabledCounter = 0;
        game.player.currPokemon.trapCounter = 0;
        game.player.currPokemon.trappedBy = null;
        game.player.currPokemon.cantEscapeBy = null;
        game.player.currPokemon.participatedInBattle = true;
        DrawBattle.prevFriendlyAttackIndex = -1;
        game.player.currPokemon.volatileStatus.clear();
        game.player.currPokemon.volatileStatusCounter.clear();
        DrawAttacksMenu.curr = 0;
    }

    @Override // com.corona.game.Action
    public void step(Game game) {
        this.sprite = this.sprites.get(0);
        if (this.sprites.size() <= 1) {
            if (!this.doneYet) {
                game.insertAction(this.nextAction);
                game.player.currPokemon.backSprite.setPosition(this.position.x, this.position.y);
                for (int k = 0; k < this.sprite.length; k++) {
                    if (this.sprite[k] != null) {
                        for (int i = 0; i < this.sprite[k].length; i++) {
                            for (int j = 0; j < this.sprite[k][i].length; j++) {
                                this.sprite[k][i][j].setPosition(this.position.x, this.position.y);
                            }
                        }
                    }
                }
                this.doneYet = true;
                this.layer = Action.Layer.gui_114;
                game.actionStack.remove(this);
                game.insertAction(this);
            }
            if (DrawBattle.shouldDrawOwnPokemon && !DrawBattle.hideOwnPokemon) {
                for (int k2 = 0; k2 < this.sprite.length; k2++) {
                    for (int i2 = 0; i2 < this.sprite[k2].length; i2++) {
                        for (int j2 = 0; j2 < this.sprite[k2][i2].length; j2++) {
                            this.sprite[k2][i2][j2].draw(game.uiBatch);
                        }
                    }
                }
            }
            if (game.battle.drawAction == null) {
                game.actionStack.remove(this);
                return;
            }
            return;
        }
        if (this.sprite != null) {
            for (int k3 = 0; k3 < this.sprite.length; k3++) {
                if (this.sprite[k3] != null) {
                    for (int i3 = 0; i3 < this.sprite[k3].length; i3++) {
                        for (int j3 = 0; j3 < this.sprite[k3][i3].length; j3++) {
                            if (this.sprite[k3][i3][j3] != null) {
                                this.sprite[k3][i3][j3].setPosition((this.position.x + ((float) (8 * i3))) - ((float) (4 * k3)), (this.position.y + ((float) (8 * j3))) - ((float) (8 * k3)));
                                this.sprite[k3][i3][j3].draw(game.uiBatch);
                            }
                        }
                    }
                }
            }
        }
        this.sound = this.sounds.get(0);
        if (this.sound != null) {
            game.insertAction(new PlaySound(this.sound, (Action) null));
            this.sounds.set(0, null);
        }
        if (this.repeats.get(0).intValue() > 1) {
            this.repeats.set(0, Integer.valueOf(this.repeats.get(0).intValue() - 1));
            return;
        }
        this.sprites.remove(0);
        this.repeats.remove(0);
        this.sounds.remove(0);
    }
}
